/**
 * Dashboard.Options
 * Drop down dialog on every dashboard page to switch between display types
 *
 * @author Seth
 * @version 0.4
 */
Dashboard.Options = function() {
	var cont = $('#context_ul'),
		silent = false,

	// autoload option
	_autoload = function() {
		var t = '<li class="sep"></li>' +
			'<li><a href="javascript:void(0);" class="lm-dashboard_sm" id="notification"></a></li>';

		// append template
		cont.append(t);

		// send load request
    	Petolio.ajax({
			url: 'dashboard/notification',
			type: 'post',
			data: {},
			cache: false,
			success: function (x) {
				var n = $('#notification');

				// transform text and set status
				n.html(_translate(x.status ? 'disable_email' : 'enable_email'));
				n.data('status', x.status);
			},
			error: function() {
				silent = true;
			}
		});

	// bind
	}, _bind = function() {
		// on li click
		cont.find('#notification').click(function(e) {
			var n = $(this);

			// show confirm dialog
			Petolio.showConfirm(_translate(n.data('status') == 1 ? 'disable_q' : 'enable_q'), function() {
				// send save request
		    	Petolio.ajax({
					url: 'dashboard/notification',
					type: 'post',
					data: {save: n.data('status')},
					cache: false,
					success: function (x) {
						// transform text and set status
						n.html(_translate(x.status ? 'disable_email' : 'enable_email'));
						n.data('status', x.status);
					}
				});
			});
		});

    // translate
	}, _translate = function(i) {
		return Dashboard.Translate.init(i);

	// constructor
	}, __construct = function() {
		_autoload();
		_bind();
	};

	// public
	return {
		init: __construct
	};
}();